package com.handinglian.ai.record.controller;

import com.apidoc.annotation.Api;
import com.handinglian.ai.common.dto.CommonPage;
import com.handinglian.ai.common.dto.ResultData;
import com.handinglian.ai.record.dto.MessageDto;
import com.handinglian.ai.record.param.MessageParam;
import com.handinglian.ai.record.service.MessageRecordService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@Api("短信记录")
@RestController
@Slf4j
@RequestMapping("/message")
public class MessageRecordController {
    @Autowired
    private MessageRecordService messageRecordService;

    /**
     * 查询短信详情
     */
    @GetMapping(value = "/get")
    public ResultData<MessageDto> get(Integer id) {
        MessageDto messageDto = messageRecordService.getDetail(id);
        return ResultData.success(messageDto);
    }

    /**
     * 获取短信列表
     */
    @GetMapping("/list")
    public ResultData<CommonPage<MessageDto>> list(String nameOrPhone, String startDate, String endDate,
                                                   @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                   @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        CommonPage<MessageDto> messageDtos = messageRecordService.listPage(nameOrPhone, startDate, endDate, pageNum, pageSize);
        return ResultData.success(messageDtos);
    }

    /**
     * 单条短信发送
     */
    @PostMapping("/sendSingleMessage")
    public ResultData sendSingleMessage(@RequestBody MessageParam messageParam) throws IOException {
        return ResultData.success(messageRecordService.sendMessage(messageParam));
    }
}
